package com.example.administrator.bdsjws.activities;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;


import com.example.administrator.bdsjws.R;
import com.example.administrator.bdsjws.activities.base.BaseActivity;
import com.example.administrator.bdsjws.fragment.UpdateVersionFragment;
import com.example.administrator.bdsjws.vo.VersionInfo;

import butterknife.BindView;

public class Activity_Update extends BaseActivity {

    @BindView(R.id.tool_bar)
    Toolbar toolbar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle("");
        findViewById(R.id.getGengXin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent=new Intent(this,);
                //startActivity(intent);
                startActivityForResult(new Intent(Activity_Update.this,Updated_popups.class),0);
            }
        });
    }
    public void showDialog(String msg){
        FragmentManager fm1=getFragmentManager();
        UpdateVersionFragment u1= UpdateVersionFragment.getUpdateVersionFragment(msg);
        u1.show(fm1,"");
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 2:
                Toast.makeText(this, "网络断了，请检查网络。。。", Toast.LENGTH_SHORT).show();
                showDialog("网络断了，请检查网络。。。");
                break;
            case 1:
                Toast.makeText(this, "有网络，但比较慢。。。", Toast.LENGTH_SHORT).show();
                showDialog("有网络，但比较慢。。。");
                break;
            case 3:
                VersionInfo versionInfo= (VersionInfo) data.getSerializableExtra("VersionInfo");
                //接收(第二个参数和第三个参数就是传过来的值) 只有3带过来两个参数，其它都只带一个参数

                Toast.makeText(this, versionInfo.getApkUrl()+"", Toast.LENGTH_SHORT).show();
                //   Toast.makeText(this, "网络正常，可以下载。。。", Toast.LENGTH_SHORT).show();
                FragmentManager fm=getFragmentManager();
                UpdateVersionFragment u= UpdateVersionFragment.getUpdateVersionFragment(versionInfo);
                //终于让对话框出现了
                u.show(fm,"");
                break;
            case 4:

                Toast.makeText(this, "网络正常，已经是最新版本。。。", Toast.LENGTH_SHORT).show();
                showDialog("网络正常，已经是最新版本。。。");
                break;
        }
    }

    @Override
    public int getContentXML() {
        return R.layout.activity__update;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

    }
}
